package org.chengn.level_middle.context2645;

/**
 * @Title: Context2645
 * @Author ChengN
 * @Package org.chengn.level_middle.context2645
 * @Date 2024/1/11 0:28
 * @description: 构造有效字符串的最少插入数
 */
public class Context2645 {
    public int addMinimum(String word) {
        int[] dp = new int[51];
        int len = word.length();
        for (int i = 0; i < len; ++i) {
            char c = i == 0 ? 'c' : word.charAt(i - 1);
            int tmp = (int)word.charAt(i) - c;
            int temp = tmp > 0 ? tmp : tmp + 3;
            dp[i + 1] = dp[i] + (temp - 1);
        }
        return word.charAt(len - 1) == 'c' ? dp[len] : dp[len] + 'c' - word.charAt(len - 1);
    }
}
